package com.designPattern.p02sampleFactory.instance;

/**
 * 食物加工工厂
 * @author: luhd
 * @create: 2021-09-02
 */
public class FoodFactory {
    public static Food getFood(String type) throws InstantiationException, IllegalAccessException {
        // 根据传入的type不同，实例化不同的对象
        if(type.equalsIgnoreCase("chicken")){
            return Chicken.class.newInstance(); //调用类的无参构造方法  实例化类的对象
        }
        if(type.equalsIgnoreCase("chips")){
            //return Chips.class.newInstance();
            return new Chips();
        } else {
            System.out.println("哎呀!找不到相应的实例化类了！");
            return null;
        }
    }
}
